import React, { PureComponent } from 'react';
import { connect } from '@@/plugin-dva/exports';
import styles from './index.less';
import UserFeedBack from "@/pages/HomePage/UserFeedback";
import Cookie from '@/utils/cookie.js';
class History extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      openModel: false,
      pageList:{
        "维度管理":{
          url:"/manager/DimensionManagement",
          id:"4028808690ac98930190aca1ed8c0005"
        },
        "维值管理": {
          url:"/manager/DimensionValueManagement",
          id:"4028808690ac98930190aca1f5c80006"
        },
        "基础指标管理": {
          url:"/manager/BasicIndexManagement",
          id:"4028808690ac98930190aca1e5930004"
        },
        "用户管理": {
          url:"/manager/UserManage",
          id:"userPage"
        },
        "角色管理": {
          url:"/manager/RoleManage",
          id:"rolePage"
        },
        "指标管理": {
          url:"/manager/IndexManagement",
          id:"indexManagement"
        },
        "用户明细": {
          url:"/manager/UserDetail",
          id:"userDetail"
        },
      },
      userId: Cookie.get('userName'),
      token: Cookie.get('token'),
    }
  }
  //初始化
  componentDidMount() {
    this.setState({
      userId: Cookie.get('userName'),
      token: Cookie.get('token')
    })
  }

  handelOk = () => {
    this.setState({openModel: true})
  }

  submitFeedback = (feedbackText)=>{
    const { dispatch } = this.props;
    dispatch({
      type: 'intellectAssistant/fetchFeedBack',
      payload: {
        question:'',
        answer:'',
        islike:'',
        feedback:feedbackText,
      },
      callback: () => {
        this.setState({
          msgVisible:false,
          type:""
        });
      },
    });
  }

  handelCancel = () => {
    this.setState({openModel: false})
  }

  render() {
    let  nowTime = Date.now()
    const {openModel,pageList,token,userId} =this.state
    const { managementName } =this.props
    const iframe= pageList[managementName].url+"?token="+token+"&id="+pageList[managementName].id+"&userId="+userId+"&time="+nowTime
    return (
      <div className={styles.content}>
        <iframe src={iframe}></iframe>
        <UserFeedBack openModel={openModel} handelOk={this.handelOk} handelCancel={this.handelCancel}
                      submitFeedback={this.submitFeedback}/>
      </div>
    );
  }
}

//这里的bonceChatGpt 是创建models时取的model名   namespace："这里的bonceChatGpt"  umi会自动识别该字段进行如下解构
export default connect(({ intellectAssistant }) => ({
  managementName: intellectAssistant.managementName,
}))(History);
